package com.tea.source.dao;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Component;

import com.tea.source.model.Pager;
@Component("pagerProductDAO")
public class PagerProductDAO extends BaseDao{  
	  
    Pager pager = new Pager(10);  
    public Pager getPager() {  
        return pager;  
    }  
    public void setPager(Pager page) {  
        this.pager = page;  
    }  
    public List getProductByPage() {  
        // TODO Auto-generated method stub   
        return getHibernateTemplate().executeFind(new HibernateCallback(){  
            public Object doInHibernate(Session session) throws HibernateException, SQLException {  
                Query query=session.createQuery("from "+pager.getPageName()+" where "+pager.getConString());  
                query.setFirstResult(pager.getBeginIndex());    
                query.setMaxResults(pager.getEveryPage());  
                return query.list();  
            }  
            });  
    }  
    public List getProducts(){  
        return getHibernateTemplate().find("from "+pager.getPageName()+" where "+pager.getConString());  
          
    }  
    public int getProductCount() {  
        // TODO Auto-generated method stub   
        List list=getHibernateTemplate().find("from "+pager.getPageName()+" where "+pager.getConString());  
        return ((Integer)list.size()).intValue();  
  
    }  
  
}  

